package com.idanchuang.component.mybatis.plus;

import com.idanchuang.component.mybatis.plus.warmup.WarmUpMybatis;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class ComponentMybatisPlusAutoConfiguration {

    @Bean("componentMybatisplusWarmUpMybatis")
    @ConditionalOnMissingBean(name = "componentMybatisplusWarmUpMybatis")
    public WarmUpMybatis warmUpMybatis(List<SqlSessionFactory> sqlSessionFactories) {
        if (sqlSessionFactories == null || sqlSessionFactories.isEmpty()) {
            return null;
        }
        return new WarmUpMybatis(sqlSessionFactories);
    }

}
